<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <textarea name="" id="textarea" cols="30" rows="10"></textarea>
    <script>
        // 5.页面上有一个多行文本输入框，当用户输入内容完成失去焦点时，如果出现以下关键词[‘子弹’,‘炸弹’,‘火炮’]，则自动替换成 ***。（考点：replace、遍历数组、blur事件）
        let arr = ["子弹", "炸弹", "火炮"]
        let textarea = document.querySelector("#textarea")
        textarea.addEventListener("blur", function () {
            // textarea.value = textarea.value.replace("子弹", "***")
            // textarea.value = textarea.value.replace("炸弹", "***")
            // textarea.value = textarea.value.replace("火炮", "***")

            arr.forEach(function (v, i) {
                if (textarea.value.indexOf(arr[i]) != -1) {
                    textarea.value = textarea.value.replace(v, "***");

                }
            })


        })
    </script>
</body>

</html>